package td3.Serialisation;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Exec {
       
        public static void ecriture(String path, Point p) {
               
                FileOutputStream f;
                ObjectOutputStream oos;
                try {
                        f = new FileOutputStream(path);
                        oos = new ObjectOutputStream(f);
                        oos.writeObject(p);
                        oos.flush();
                        oos.close();
                } catch(FileNotFoundException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }
       
        public static void lecture(String path) {
                FileInputStream f;
                ObjectInputStream ois;
                Point p;
                try {
                        f = new FileInputStream(path);
                        ois = new ObjectInputStream(f);
                        p = (Point)ois.readObject();
                        ois.close();
                        System.out.println(p);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
       
        public static void main(String[] args) {
                Point p = new Point(100, 20);
                System.out.println("Ecriture...");
                Exec.ecriture("a.dat", p);
                System.out.println("Lecture...");
                Exec.lecture("a.dat");
        }
}


